package cn.topcodes.tcsf.app.web.controller.api;

import cn.topcodes.tcsf.admin.commons.api.domain.ApiResponseEntity;
import cn.topcodes.tcsf.admin.commons.domain.Page;
import cn.topcodes.tcsf.app.domain.entity.Notice;
import cn.topcodes.tcsf.app.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统通知
 * @author Unicorn
 * @date 2017/5/5
 */
@Api(tags = {"APP通用接口(公告)"})
@RestController
@RequestMapping(value = "/api/app/notice", produces = "application/json")
public class NoticeApi {

    @Autowired
    private NoticeService noticeService;

    /*系统公告列表*/
    @ApiOperation("系统公告列表")
    @RequestMapping(value = "page-list",method = RequestMethod.GET)
    public ApiResponseEntity pageList(
            @RequestParam(required = false, name = "page", defaultValue = "1") Integer pageNumber,
            @RequestParam(required = false, name = "size", defaultValue = "20") Integer pageSize
    ) {
        Page<Notice> notices = this.noticeService.findPageBy(pageNumber, pageSize);
        return ApiResponseEntity.buildOK(notices);
    }

    @ApiOperation("系统公告详情")
    @RequestMapping(value = "detail",method = RequestMethod.GET)
    public ApiResponseEntity detail(
            @RequestParam Long id
    ) {
        Notice notice = this.noticeService.findOne(id);
        return ApiResponseEntity.buildOK().setBody(notice);
    }

    @ApiOperation("最新系统公告")
    @RequestMapping(value = "recent",method = RequestMethod.GET)
    public ApiResponseEntity recent() {
        Notice notice = this.noticeService.getLastNotice();
        return ApiResponseEntity.buildOK(notice);
    }
}
